package com.ys.day28.socket通信方式;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

/**
 * 描述: TODO
 *
 * @author CodeYang
 * @version 2021/1/8 20:59
 */
public class MyClient1 {


//    枚举,类的模拟实现原则
//    public static  MyClient s = new MyClient();
//
//    private MyClient1() {
//    }

    public static void main(String[] args)  throws Exception{
        Socket socket = new Socket("localhost", 8080);
        System.out.println("和服务端建立连接");

        OutputStream outputStream = socket.getOutputStream();
        outputStream.write("tcp----one---accept".getBytes());
        outputStream.write(-1);
        outputStream.flush();
        InputStream inputStream = socket.getInputStream();

        byte[] bs = new byte[1024];
        int len = 0;
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        while ((len = inputStream.read(bs)) != -1) {
            byteArrayOutputStream.write(bs, 0, len);
        }
        byte[] bytes = byteArrayOutputStream.toByteArray();
        String msg = new String(bytes);
        System.out.println(msg);


        MyServer1.closeRes(inputStream,outputStream,socket);
    }
}
